
<html>

<head>
    <include file="public@head" title="添加管理员-系统设置" />
    <link rel="stylesheet" href="/static/css/tags.css" rel="stylesheet">
</head>

<body class="layui-layout-admin">
    <include file="public@header" />
    <include file="public@side" />
    <div class="layui-body">
        <div class="layui-breadcrumb" lay-filter="breadcrumb">
            <a href="{:url('tdadmin/index/index')}">主页</a>
            <a href="">系统设置</a>
            <a href="{:url('tdadmin/teacher/index')}">教师列表</a>
            <a><cite>添加教师</cite></a>
        </div>

        <div class="layui-fluid mgt10">
            <div class="layui-card">
                <div class="layui-card-header">
                    添加教师
                </div>
                <div class="layui-card-body">
                    <form method="post" id="userForm" action="{:url('insertTeacher')}" class="layui-form"  enctype="multipart/form-data">
                        <div class="layui-form-item">
                            <label class="layui-form-label">文件<span class="form-required">*</span></label>
                            <div class="layui-input-inline">
                                <input id="file" type="file" class="layui-input" name="file"
                                    lay-verify="required" lay-verType="tips" placeholder="文件上传">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button type="submit" class="layui-btn" lay-filter="insert">添加</button>
                                <a class="layui-btn layui-btn-primary" href="javascript:history.back(-1);">返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <include file="public@scripts" />
    <script type="text/javascript">
        var layer = layui.layer,
            $ = layui.jquery,
            form = layui.form;

        form.on('submit(insert)', function (data) {
            layer.load();
            var formData = new FormData($("#userForm")[0]);


            $.ajax({
                cache: true,
                type: "post",
                url: "insertTeacher",
                async: true,
                data: formData,
                contentType: false,   //jax 中 contentType 设置为 false 是为了避免 JQuery 对其操作，从而失去分界符，而使服务器不能正常解析文件
                processData: false,   //当设置为true的时候,jquery ajax 提交的时候不会序列化 data，而是直接使用data
                error: function (request) {
                    layer.alert('操作失败', {
                        icon: 2,
                        title: "提示"
                    });
                    layer.closeAll();
                },
                success: function (ret) {
                    if (ret.code == 0) {
                        layer.alert(ret.msg, {
                            icon: 2,
                            title: "提示"
                        });
                    } else {
                        layer.alert(ret.msg, {
                            icon: 1,
                            title: "提示"
                        });

                        window.location.reload();
                    }
                    layer.closeAll();
                }
            })
        });

    </script>
</body>

</html>